package com.yehebl.handler.manager;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

/**
 * 参数map
 *
 * @author tzd
 */
public class ParameterTypeManager {
    private Map<String, Class<?>[]> map = new HashMap<String, Class<?>[]>();
    private Map<String, Set<Class<?>>> hashSet = new HashMap<String, Set<Class<?>>>();

    /**
     * 添加参数map
     *
     * @param key
     * @param clazzs
     */
    public void add(String key, Class<?>[] clazzs) {
        if (map.containsKey(key)) {
            throw new RuntimeException("处理器[" + key + "]重复");
        }
        Set<Class<?>> set = new HashSet<Class<?>>();
        if (clazzs != null) {
            for (int i = 0; i < clazzs.length; i++) {
                set.add(clazzs[i]);
            }
        }
        hashSet.put(key, set);
        map.put(key, clazzs);
    }

    public Class<?>[] get(String key) {
        if (!map.containsKey(key)) {
            throw new RuntimeException("找不到处理器[" + key + "]");
        }
        return map.get(key);
    }

    public boolean isExistType(String key, Class<?> clazz) {
        Set<Class<?>> set = hashSet.get(key);
        if (set != null) {
            return set.contains(clazz);
        }
        return false;
    }
}
